#define _MINIX 1
#include <sys/types.h>
#include <minix/config.h>
#include <minix/const.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

extern int _chhid(const char *_path, Mode_t _mode);		
int
usage(void)
{
	fprintf(stderr, "Usage: chhid -hHoOgGpPs archivo\n");
	exit(1);
}
int
main(int argc, char** argv)
{
	int r;
	int opt;
	int mode;
	if (argc != 3 || argv[1][0] != '-')
	{
		usage();
	}
	mode=NO_HIDDEN;
	while( (opt = getopt(argc, argv, "hHoOgGpPs")) != EOF)
		switch(opt) {
			case 'h':
				mode |= (O_HIDDEN|G_HIDDEN);
				mode |= (O_MOD_HIDDEN|G_MOD_HIDDEN);
				break;
			case 'H':
				mode &= ~(O_HIDDEN|G_HIDDEN);
				mode |= (O_MOD_HIDDEN|G_MOD_HIDDEN);
				break;
			case 'o':
				mode |= O_HIDDEN;
				mode |= O_MOD_HIDDEN;
				break;
			case 'O':
				mode &= ~O_HIDDEN;
				mode |= O_MOD_HIDDEN;
				break;
			case 'g':
				mode |= G_HIDDEN;
				mode |= G_MOD_HIDDEN;
				break;
			case 'G':
				mode &= ~G_HIDDEN;
				mode |= G_MOD_HIDDEN;
				break;
			case 'p':
				mode |= P_HIDDEN;
				mode |= P_MOD_HIDDEN;
				break;
			case 'P':
				mode &= ~P_HIDDEN;
				mode |= P_MOD_HIDDEN;
				break;
			case 's':
				mode = 0;
				continue;
			default:
				usage();
				break;
		}
	r=_chhid(argv[2], mode);
	if (r != 0)
		perror(argv[2]);
	return r;
}

